<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
	<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="../../common/base.jsp"%>
<%
	response.setCharacterEncoding("utf-8");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link href="${path }/dist/css/bootstrap.css" rel="stylesheet">
<link href="${path }/dist/css/bootstrap-overrides.css" rel="stylesheet">

<!-- Button -->
<link href="${path }/dist/css/compiled/elements.css" rel="stylesheet">
<!-- libraries -->
<link rel="stylesheet" type="text/css"  href="${path }/dist/css/font-awesome.css">
<!-- this -->
<link rel="stylesheet" type="text/css" href="${path }/dist/css/app.css">
<link href='${path }/dist/css/zTreeStyle/zTreeStyle.css' rel='stylesheet' />
<link href="${path }/dist/css/bootstrap-datetimepicker.min.css" rel="stylesheet"><%--时间日期工具 --%>
<!-- 右键菜单插件 -->
<link rel="stylesheet" type="text/css" href="${path }/dist/css/smartMenu.css">

<link rel="stylesheet" type="text/css" href="${path }/back/ifrom.css">
<script src="${path }/dist/js/jquery.min.js"></script>
<script src='${path }/dist/js/bootstrap.min.js'></script>
<script src="${path }/dist/js/theme.js"></script>
<script src='${path }/dist/js/jquery-smartMenu.js'></script>
<script src='${path }/dist/js/jquery.ztree.core-3.5.js'></script>
<script src='${path }/dist/js/jquery.ztree.excheck-3.5.js'></script>
<script src='${path }/dist/js/jquery.ztree.exedit-3.5.js'></script>
<script src="${path }/dist/js/bootstrap-datetimepicker.min.js"></script>
<script src="${path }/dist/js/bootstrap-datetimepicker.zh-CN.js"></script>

<style>
table tr>td.title{
		width: 85px;
		padding-right: 0px;
	}
.left_tree{
	height: 430px;
	overflow: auto;
	border: 1px solid #ccc;
	 border-radius: 5px;
}
#pad-wrapper h3{
	font-family: "黑体";
}
#from_table th{
	padding: 10px 0;
	cursor: pointer;
}
#from_table input,
#from_table input:hover,
#from_table input:focus{
	border-left: none !important;
	border-right: none !important;
	border-top: none !important;
	background-color: transparent !important;
	color: #000 !important;
	box-shadow:none !important;
}
#from_table input[readonly]{
	cursor: pointer;
}
#node_tbody input[readonly]{
	cursor: text;
	background-color: transparent;
	border: none;
	color: #000;
	box-shadow:none !important;
}
#node_tbody *{
color: #000;
}
.table tr>td{
	padding:  2px 5px;
	max-width: 100px;
	height: 20px;
}
.table tr>td select{
	width: 100%;
}
.panel-body span.tip{
	float: right;
}
.menuContent {padding-top: 10px;border: 1px solid #617775;background: #f0f6e4;width:160px;height:260px;overflow-y:scroll;overflow-x:auto;}
.btn-group-vertical{
	width: 100%;
}
i{
	margin-right: 5px;
}
.tip{
	text-align: right;
	font-size: 12px;
	color: #ccc;
}
.my_input {
  height: 34px;
  font-size: 14px;
  line-height: 1.428571429;
  vertical-align: middle;
}
</style>
</head>
<bady>


<div class="container-fluid" style="padding: 0 50px 0 50px;">
	<div class="row head">
	<div class="col-sm-12">
			<h3>资产盘点<em><small>盘点资产时切勿刷新页面，以免造成数据丢失</small></em></h3>
			</div>
	</div>
	<hr>
	<form action="${path}/back/assetsPD!sevaInventory" method="post" id="inventory_from">
	<div class="row">
		<div class="panel panel-default">
			<div class="jumbotron" style="text-align: center;">
				  <h2>福建XXX公司有限公司</h2>
				  <p>盘点</p>
				  <h6 >盘点时间为每月月底最后3天，其他时间不可盘点</h6>
			</div>
		<div class="panel-body" style="padding: 0px;">

				<table class="table-hover" id='from_table'>
						<tr>
							<td>单据号</td>
							<td><input type="text" name='receiptBean.no' class="form-control input-sm" value="${receipt_no }"/></td>
							<td>盘点人</td>
							<td><input type="text" name="receiptBean.user_id" class="form-control input-sm" value="${user.user_account }"  readonly="readonly"/></td>
							<td>系统数量：</td>
							<td style="width: 80px;"><input type="text" name="receiptBean.sys_amount" class="form-control input-sm" value="${inventoryList[fn:length(inventoryList)-1]['amount'] }" readonly="readonly" id="txt_sys_amount"/></td>
							<td>实际数量：</td>
							<td style="width: 80px;"><input type="text" name="receiptBean.real_amount" class="form-control input-sm" value="${inventoryList[fn:length(inventoryList)-1]['amount'] }" readonly="readonly" id="txt_real_amount"/></td>
							<td>差异：</td>
							<td style="width: 80px;"><input type="text" name="receiptBean.d_amount" class="form-control input-sm" value="0" readonly="readonly" id="txt_d_amount"/></td>
							<td rowspan="2" width="220px;">
								<button type="button" class="btn btn-success btn-lg btn-block" onclick="sevainventory()">保存盘点</button>
								<button type="button" class="btn btn-info  btn-sm btn-block" onclick="fold()"><i class="icon-time"></i><span>计提折旧</span></button>
							</td>
						</tr>
						<tr>
							<td>单据摘要</td>
							<td colspan="5"><input type="text" class="form-control input-sm" name="receiptBean.receipt_remark" 
								readonly="readonly" value="[福建XXX公司有限公司 全部资产] 盘点资料"/></td>
							<td>盘点日期:</td>
							<td colspan="3"><input type="text" class="form-control input-sm form_datetime" name="receiptBean.receipt_data" 
								readonly="readonly" value="<fmt:formatDate value="${date}" pattern="yyyy-MM-dd"/>"/></td>
						</tr>
				</table>
				 <span class='tip'>蓝：盘盈，黑：无差异，红：盘亏</span> 
			<div class="row" style="margin-bottom: 10px;margin: 0px;">
				<div class="col-sm-12">
						<table class="table table-striped">
							<thead>
									<tr id="table_title" class="table_title">
										<th class="sortable" width="50px;"><span>#</span ></th>
										<th class="sortable" ><span class="line"></span><span>资产分类</span ></th>
										<th class="sortable" ><span class="line"></span><span >资产名称</span></th>
										<th class="sortable" width="100px"><span class="line"></span><span >计量单位</span></th>
										<th class="sortable" width="100px"><span class="line"></span><span >资产状态</span></th>
										<th class="sortable" width="120px"><span class="line"></span><span >资产单价</span></th>
										<th class="sortable" width="100px" ><span class="line"></span><span >使用部门</span></th>
										<th class="sortable" width="70px"><span class="line"></span><span >数量</span></th>
										<th class="sortable" width="100px"><span class="line"></span><span >实盘数量</span></th>
										<th class="sortable" width="100px"><span class="line"></span><span >差异</span></th>
									</tr>
								</thead>
								<tbody id="node_tbody" >
								<c:if test="${(fn:length(inventoryList))>1}">
									<c:forEach begin="0" end="${fn:length(inventoryList) - 2}" var="i">
										<tr>
											<td>#</td>
											<td><input type="text" class="my_input " name='receiptdetailslist[${i}].assets_class_name' value="${inventoryList[i]['a_class_name'] }" readonly="readonly"/> </td>
											<td><input type="text" class="my_input " name='receiptdetailslist[${i}].assets_name' value="${inventoryList[i]['a_name'] }" readonly="readonly"/></td>
											<td>${inventoryList[i]['a_measure'] }</td>
											<td><input type="text" class="my_input " name='receiptdetailslist[${i}].assets_status' value="${inventoryList[i]['a_status'] }" readonly="readonly"/></td>
											<td>￥<fmt:formatNumber value="${inventoryList[i]['a_unit_price'] }" pattern="#,#00.00#" /><input type="hidden" name='receiptdetailslist[${i}].assets_money' value="${inventoryList[i]['a_unit_price'] }"/></td>
											<td><input type="text" class="my_input " name='receiptdetailslist[${i}].use_dept_name' value="${inventoryList[i]['a_use_dept'] }" readonly="readonly"/></td>
											<td><input type="text" class="my_input " name='receiptdetailslist[${i}].assets_num' value="${inventoryList[i]['amount'] }" readonly="readonly"/></td>
											<td><input type="text" name='receiptdetailslist[${i}].real_num' type="text" value="${inventoryList[i]['amount'] }" class="form-control input-sm" /></td>
											<td><input type="text" class="my_input " name='receiptdetailslist[${i}].difference' value='0' readonly="readonly"/></td>
										</tr>
									</c:forEach>
									</c:if>
								</tbody>
								<tfoot>
									<tr>
										<td>小计</td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td><fmt:formatNumber value="${inventoryList[fn:length(inventoryList)-1]['a_unit_price'] }" pattern="￥#,#00.00#"/></td>
										<td></td>
										<td>${inventoryList[fn:length(inventoryList)-1]['amount'] }</td>
										<td></td>
										
									</tr>
								</tfoot>
						</table>
				</div>
			</div>
		</div>
	</div>
	</form>
	</div>
</div>

	<script type="text/javascript">
	 Array.prototype.indexOf = function(val) {
         for (var i = 0; i < this.length; i++) {
             if (this[i] == val) return i;
         }
         return -1;
     };
     Array.prototype.remove = function(val) {
         var index = this.indexOf(val);
         if (index > -1) {
             this.splice(index, 1);
         }
     };
     function sevainventory(){

    	if(!isPass()){
    		 alert("今天不可盘点");
    		 return;
    	}else{
    		$("#inventory_from").submit();
    	}
    		
     }
     function isPass(){
    	 var currentDate= new Date();
    	 var month = currentDate.getMonth();
    	 var day=currentDate.getDate();
    	 var ispass=false;
    	 if(month==2){
    		 if(day>=25&&day<=28)
    	 		ispass=true;
    	 }else{
    		 if(day>=28&&day<=31)
    			 ispass=true;
    	 }
    	 return ispass;
     }
     function fold(){
    	 if(!isPass()){
    		 alert("今天不可折旧");
    		 return;
    	}else{
    		var saveURL = "${path}/back/assetsMS!fold?date="+new Date()+"";
     		jQuery.post(saveURL,null,function(data){
     			if(data.info)
     					alert(data.text);
     			window.location.reload(true);
     		},'json'); 
    	}
 		
 	}
	$(document).ready(function() {
		$("#node_tbody input[name*='real_num']").keyup(function(){
			$(this).val($(this).val().replace(/\D/g,''));
			var count=0;
			$("#node_tbody input[name*='real_num']").each(function(){
				count+=$(this).val()*1;
			});
			$("#txt_real_amount").val(count);
			var tdobj=$(this).parent();
			var sysnum=tdobj.prev().find("input").val();
			var difference=$(this).val()*1-sysnum*1;
			var dobj=tdobj.next().find("input");
			dobj.val(difference);
			$("#txt_d_amount").val($("#txt_real_amount").val()*1-$("#txt_sys_amount").val()*1);
			if(difference>0)
				dobj.css({color:"#00f"});
			else if(difference==0)
				dobj.css({color:"#000"});
			else if(difference<0)
				dobj.css({color:"#f00"});
			
		});
	});
	//时间日期
	$(".form_datetime").datetimepicker({format: 'yyyy-mm-dd',language:  'zh-CN',weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0,
        showMeridian: 1,
        minView: 2,
        pickerPosition:"bottom-left"});
	//判断表单导游data-vail 属性是否为空
	function fromisnotnull(fromdom){
		var  pass =true;
		$("input[type='text'][data-vail]",fromdom).each(function(){
			if($(this).val()==null||$(this).val()==""){
				alert("红色为必填项");
				pass =false;
				return false;
			}
		});
		return pass;
	}
	function onBodyDown(evetnt){
		if(!($(evetnt.target).closest(evetnt.data.id).length>0)){
			hidetree(evetnt.data.id);
		}
	}
	//解除 body绑定
	function hidetree(id){
		$(id+"").fadeOut("fast");
		$("body").unbind("mousedown",onBodyDown);
	}
	</script>
	<c:if test="${tip!=null }">
<script type="text/javascript">
 alert('${tip}');
</script>
</c:if>
</bady>
</html>
